import axios from 'axios'

function ajax_get(path, params) {
    return new Promise(function (resolve, reject) {
        axios.get(path, {
            params
        }).then(result => {
            resolve(result.data)
        })
    })
}

var qs = require('qs')
function ajax_post(path,params){
    return new Promise(function(resolve,reject){
        // console.log(params)
        // console.log(qs.stringify(params))
        axios.post(path, qs.stringify(params)).then(result => {
            resolve(result.data);
        })
    })
}
import $ from "./jquery.js"
function ajax_post1(path, params) {
    // console.log(params)
    return new Promise(function (resolve, reject) {
        //  axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        // $.post(path, qs.stringify(params)).then(result => {
        //     resolve(result);
        // })
        $.ajax({
            url:path,
            type:'POST',
            data:params,
            async:false,
            cache:false,
            contentType:false,
            processData:false,
            success:function(data){
                resolve(data)
            }
        })

    })
}

//搜索
function ajax_search(params){
    return ajax_get('/myE/search',params);
}
//登录请求
function ajax_login(params){
    return ajax_post('/myE/Login',params);
}
//注册
function ajax_register(params){
    return ajax_post('/myE/Register',params)
}

//获取商铺信息
function ajax_shopList(params){
    return ajax_post('/myE/shopList',params)
}
//获取食品推荐列表
function ajax_tjFood(params){
    return ajax_post('/myE/tjFood',params)
}
//获取所有食品
function ajax_Food(params){
    return ajax_get("/myE/Food",params)
}
//下单
function ajax_ding(params){
    return ajax_get("/myE/ding",params)
}
//获取用户订单列表
function ajax_dDList(params){
    return ajax_get('/myE/userDd',params)
}
//修改用户手机号
function ajax_phone(params){
    return ajax_post('/myE/phone',params);
}
//上传用户头像
function ajax_headImg(params){
    return ajax_post1('/myE/headImg',params);
}
//新增用户地址
function ajax_addAddress(params){
    return ajax_post("/myE/addAddress",params);
}
//地址列表
function ajax_getAddress(params){
    return ajax_get("/myE/getAddress",params)
}
//确认收货
function ajax_trueShou(params){
    return ajax_post("/myE/updateDing",params)
}
//上传评价照片
function ajax_pingImg(params){
    return ajax_post1("/myE/pingImg",params)
}
//上传评价
function ajax_pingJia(params){
    return ajax_post("/myE/pingJia",params);
}
//获取评论
function ajax_getPing(params){
    return ajax_get("/myE/getPingJia",params)
}
export {
    ajax_search,
    ajax_login,
    ajax_register,
    ajax_shopList,
    ajax_tjFood,
    ajax_Food,
    ajax_ding,
    ajax_dDList,
    ajax_phone,
    ajax_headImg,
    ajax_addAddress,
    ajax_getAddress,
    ajax_trueShou,
    ajax_pingImg,
    ajax_pingJia,
    ajax_getPing,
}